
@extends('common.header')

<!-- 1.添加meta csrf_token -->
<meta name="csrf-token" content="{{ csrf_token() }}">  
<script src=" {{ asset('/js/jquery-1.8.3.min.js') }} "></script>


<body>
<br/>
<br/>
<br/>
<br/>

<!-- 页面标记 -->
<h3 style="margin-left:10%;color:#32CD32;font-size:25px;" >
	{{ $title or '' }}
</h3>
<div class="row" style="margin-top:87px;width:98%;margin-bottom:70px;">
	<div class="col-xs-6 col-md-2">
	
	</div>
	<div class="col-xs-12 col-md-6"  >
		<!-- 网站名称 -->
		<div  class="form-group">
			<label class="col-sm-2 control-label">网站名称</label>
			<div class="col-sm-10">
				<input type="text" name="name" value="{{ $link->name or '' }}" class="form-control" style="width:300px;"  placeholder="网站名称" />
			</div>
		</div>

		<br/><br/><br/>
		
		<div  class="form-group">
			<label class="col-sm-2 control-label">链接地址</label>
			<div class="col-sm-10">
				<input type="text" name="url" value="{{ $link->url or '' }}" class="form-control" style="width:300px;"  placeholder="链接地址" />
			</div>
		</div>
		
		
		
		<br/>
		<br/>
		<br/>
		
		
		@if( isset($link) )
			<button  style="width:320px;;margin-left:8%;" data-toggle="modal" data-target=".bs-example-modal-sm" class="btn btn-danger" id="">修改
			</button>
		@else
			<button  style="width:320px;margin-left:8%;" data-toggle="modal" data-target=".bs-example-modal-sm" class="btn btn-danger" id="">添加
			</button>
		@endif
		
		
		<div  class="form-group" style="margin-top:30px;">
			<a href="javascript:history.back();" style="width:320px;margin-left:8%;" class="btn btn-success">
				返回
			</a>
		</div>
		
		
		<!-- 1.模态框 不要动 -->
		<div class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel">
			<div class="modal-dialog modal-sm" role="document" id='show_info'  style="margin-top:5%;margin-left:40%;color:white;font-size:20px;">
			</div>
		</div>
	</div>
</div>
	
	


<div id="linkId" value="{{ $link->id or ''}}" ></div>
<script>
	<!-- 2.设置全局ajax选项 -->
	$.ajaxSetup({
		headers: {
			'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
		}
	});
	var _token = $('meta[name="csrf-token"]').attr('content');

	$(function(){

	
		// 点击 执行 友情链接 创建 编辑
		$("button").click(function(){
			var link_id = $("#linkId").attr('value');
			if( link_id!='' )
			{
				// 编辑
				var sendUrl ="{{ url('/friend/doCreate') }}"+'/'+link_id;
				
			}else
			{
				// 创建
				var sendUrl ="{{ url('/friend/doCreate') }}";
			}
			var name = $("input[name='name']").val();
			var url = $("input[name='url']").val();
			$.ajax({
				type:"post",
				url:sendUrl,
				data:{url:url,name:name,_token:_token},
				async:true,    						
				dataType:"json",
				success:function(back){
					$('#show_info').html( '' );
					$('#show_info').html( back['show_info'] );
					if( back['show_info']=='修改链接成功' || back['show_info']=='添加链接成功' )
					{
						location.href="{{ url('/friend/list') }}";
					}
				}
			});
		});

	});
</script>
</body>

@extends('common.footer')